package jiejie.jianzhioffer;

import java.util.Arrays;

public class offer21 {
    public static void main(String[] args) {
        int[] nums={11,9,3,7,16,4,2,0};
        int[] res=exchange(nums);
        System.out.println(Arrays.toString(res));
    }

    public static int[] exchange(int[] nums) {
        if(nums.length==0 || nums.length==1)
            return nums;
        int left=0;
        int right=nums.length-1;
        while(left<right){
            if(nums[left]%2==1)
                left++;
            else if(nums[right]%2==0)
                right--;
            else if(nums[left]%2==0 && nums[right]%2==1){
                int tmp=nums[left];
                nums[left++]=nums[right];
                nums[right--]=tmp;
            }
        }
        return nums;
    }
}